package cappuccino.couldbook.ui;

import android.content.DialogInterface;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import java.util.List;

import cappuccino.couldbook.R;
import cappuccino.couldbook.base.BaseActivity;
import cappuccino.couldbook.core.mananger.AccountM;
import cappuccino.couldbook.data.Group;
import cappuccino.couldbook.data.Result;
import cappuccino.couldbook.net.Network;
import cappuccino.couldbook.ui.Adapter.RecylerGroupsAdapter;
import rx.Observer;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by Administrator on 2016/9/10.
 */
public class SearchActivity extends BaseActivity {

    String TAG = "GroupsActivity";
    private RecyclerView show;
    private Toolbar toolbar;
    int status = 0;

    @Override
    protected void bindView() {
        setContentView(R.layout.activity_group);
        show = (RecyclerView) findViewById(R.id.tv_group_show);
        String name = getIntent().getStringExtra("group_name");
            status = 2;
            AccountM accountM = new AccountM(this);
            int id = accountM.getAccout();
            if (id == -1) {
                Toast.makeText(this, "请先登录", Toast.LENGTH_SHORT).show();
            } else {
                Network.getNetApi().getGroups(name).subscribeOn(Schedulers.io())
                        .observeOn(AndroidSchedulers.mainThread())
                        .subscribe(observer);
            }

    }



    @Override
    protected void init() {

    }

    Observer<Result<List<Group>>> observer = new Observer<Result<List<Group>>>() {
        @Override
        public void onCompleted() {

        }

        @Override
        public void onError(Throwable e) {

        }

        @Override
        public void onNext(Result<List<Group>> listResult) {
            RecylerGroupsAdapter adapter = new RecylerGroupsAdapter(SearchActivity.this, listResult.data,status);
            show.setAdapter(adapter);
            show.setLayoutManager(new LinearLayoutManager(SearchActivity.this));
        }
    };
}
